import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
// import whoami from '@dfeidao/atom-web/msg/whoami';
import set from '@dfeidao/atom-web/local/set';
import nodejs from "@dfeidao/atom-web/msg/nodejs";
import render from "@dfeidao/atom-web/render/render";
import s_get from '@dfeidao/atom-web/storage/get';
import p001 from './p001';


export default async function a005(fd: IFeidaoAiBrowserComponent, args: Event) {
	//  调用事件
	const node1 = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-zj="zj"]');
	node1.classList.remove('display-n');

	const id = args;
	// fd.data.id = id;
	set(fd, 'id', id);
	// const user = await whoami(get_user_info);
	// console.log(user)

	const prid = await s_get('productid');

	const query = {
		filter: {
			_id: id
		},
		productid: prid
	};
	// console.log(query)
	const res = await nodejs<{ dataArray: Array<{ usercode: string, avatar_path: string }> }>('consumer/zj-000003/consumer-find', query);
	// console.log(res.dataArray[0]['usercode'])
	// if (res.dataArray.length !== 0) {
	set(fd, 'oldcode', res.dataArray[0].usercode);
	const tb = res.dataArray;
	const data = tb.map((v) => {
		return { ...v, v: JSON.stringify(v) };
	});
	const arr = new Array();
	if (data[0].avatar_path) {
		arr.push(data[0].avatar_path);
		set(fd, 'beau', arr);
	}
	render(fd, data, p001, 'p001', 'inner');
	// } else {
	// 	set(fd, 'oldcode', '');
	// 	render(fd, '', p001, 'p001', 'inner');
	// }
}
